package com.emsys.web.controller.equipment;

import com.emsys.common.annotation.Log;
import com.emsys.common.base.AjaxResult;
import com.emsys.common.enums.BusinessType;
import com.emsys.common.utils.ExcelUtil;
import com.emsys.equipment.domain.EquipInfo;
import com.emsys.equipment.service.IEquipInfoService;
import com.emsys.framework.util.ShiroUtils;
import com.emsys.framework.web.page.TableDataInfo;
import com.emsys.web.core.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 建账审核操作处理
 * （注意，本功能之下的查找设备信息，可以包含待审核和已审核信息）
 * （注意，本功能之下的查找设备信息，都是报废待审核状态下的）
 * @author zhangpeng
 * @date 2018-11-02
 */
@Controller
@RequestMapping("/equipment/audit")
public class EquipAuditController extends BaseController {
	//注意，本功能之下的查找设备信息，都是报废待审核状态下的
	private static final String SCRAPAUDIT = "0";

    private String prefix = "equipment/audit";
	
	@Autowired
	private IEquipInfoService equipInfoService;
	
	@RequiresPermissions("equipment:audit:view")
	@GetMapping()
	public String info()
	{
	    return prefix + "/equipInfo";
	}
	
	/**
	 * 条件分页查询设备列表
	 */
	@RequiresPermissions("equipment:audit:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(EquipInfo equipInfo )
	{
		equipInfo.setScrapaudit(SCRAPAUDIT);
		startPage();
        List<EquipInfo> list = equipInfoService.selectInfoList(equipInfo);
		return getDataTable(list);
	}

    /**
     * 设备导出
     */
    @Log(title = "建账审核", businessType = BusinessType.EXPORT)
    @RequiresPermissions("equipment:audit:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EquipInfo equipInfo)
    {
		equipInfo.setScrapaudit(SCRAPAUDIT);
        List<EquipInfo> list = equipInfoService.selectInfoList(equipInfo);
        ExcelUtil<EquipInfo> util = new ExcelUtil<>(EquipInfo.class);
        return util.exportExcel(list, "EquipInfo");
    }

	/**
	 * 详情
	 */
	@RequiresPermissions("equipment:audit:detail")
	@GetMapping("/detail/{equipId}")
	public String detail(@PathVariable("equipId") Long equipId, ModelMap mmap)
	{
		mmap.put("equipInfo", equipInfoService.selectInfoById(equipId));
		return prefix + "/detail";
	}

	/**
	 * 审核通过
	 */
	@RequiresPermissions("equipment:audit:pass")
	@Log(title = "建账审核", businessType = BusinessType.UPDATE)
	@PostMapping( "/pass")
	@ResponseBody
	public AjaxResult editSave(String ids)
	{
		return toAjax(equipInfoService.passAuditByIds(ids));
	}

}
